/**
 * MacroCommand.java
 *
 * Provider: CoderDream's Studio
 *
 * History
 *	Date(DD/MM/YYYY)    Author          Description
 * ----------------------------------------------------------------------------
 *	Nov 5, 2007		CoderDream		Created
 */
package com.coderdream.chapter22.command.sample.command;

import java.util.Iterator;
import java.util.Stack;

/**
 * <pre>
 * MacroCommand.java
 * </pre>
 * 
 */
public class MacroCommand implements Command {

	private Stack commands = new Stack();

	/**
	 * 
	 */
	public void execute() {
		Iterator it = commands.iterator();
		while (it.hasNext()) {
			((Command) it.next()).execute();
		}
	}

	/**
	 * Add
	 * 
	 * @param cmd
	 */
	public void append(Command cmd) {
		if (cmd != null) {
			commands.push(cmd);
		}
	}

	/**
	 * Delete the last command
	 * 
	 * @param cmd
	 */
	public void undo() {
		if (!commands.empty()) {
			commands.pop();
		}
	}

	/**
	 * Delete All
	 */
	public void clear() {
		commands.clear();
	}

}
